package com.example.meitao.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.example.meitao.R;

public class GradeActivity extends AppCompatActivity implements View.OnClickListener {

    private Toolbar mToolbar;
    private ImageView mIv_Photo;
    private PopupWindow mPopupWindow;
    private TextView mTextViewDismiss;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_grade);
        initView();
        setOnListener();
    }

    private void setOnListener() {
        mIv_Photo.setOnClickListener(this);
    }

    private void initView() {
        mIv_Photo = (ImageView)findViewById(R.id.iv_grade_photo);
        mToolbar = (Toolbar)findViewById(R.id.tb_grade);
        //把actiobar换成toolbar
        setSupportActionBar(mToolbar);
    }

    private void initPopupWindow() {
        //设置contentView
        View contentView = LayoutInflater.from(this).inflate(R.layout.grade_layout, null);
        mPopupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,true);
        mPopupWindow.setContentView(contentView);

        //TODO 设置各个控件的点击事件
        mTextViewDismiss = (TextView)contentView.findViewById(R.id.tv_grade_dismiss);
        mTextViewDismiss.setOnClickListener(this);

        //显示PopupWindow
        View rootview = LayoutInflater.from(GradeActivity.this).inflate(R.layout.activity_grade, null);
        mPopupWindow.setAnimationStyle(R.style.popupwindowAnim);
        mPopupWindow.showAtLocation(rootview, Gravity.BOTTOM, 0, 0);

    }

    @Override
    public void onClick(View view) {
       if(view!=null) {
           switch (view.getId()) {
               case R.id.iv_grade_photo :
                   initPopupWindow();
                   break;
               case R.id.tv_grade_dismiss:
                    mPopupWindow.dismiss();
                   break;
           }
       }
    }
}
